// Playground - noun: a place where people can play

import Cocoa

var str = "Hello, playground"

enum Coin: Int
{
    case SilverDollar = 100
    case HalfDollar = 50
    case Quarter = 25
    case Dime = 10
    case Nickel = 5
    case Penny = 1
    
    static func coinsInDescendingOrder() -> [Coin] {
        return [
            Coin.SilverDollar,
            Coin.HalfDollar,
            Coin.Quarter,
            Coin.Dime,
            Coin.Nickel,
            Coin.Penny
        ]
    }
}

// 
  func countWaysToBreakAmout(amout: Int, usingCoins coins:[Coin]) -> Int {
    
    let coin = coins[0]
    if (coin == .Penny) {
        return 1
    }
    
    var smallerCoins = [Coin]()
    for index in 1..<coins.count {
      smallerCoins.append(coins[index])
    }
    
    var sum = 0

    for coinCount  in 0...(amout / coin.rawValue) {
        let remainingAmount = amout - (coin.rawValue * coinCount)
        sum += countWaysToBreakAmout(remainingAmount, usingCoins: smallerCoins)
    }
    
    return sum
}

let coins = [
    Coin.SilverDollar,
    Coin.HalfDollar,
    Coin.Quarter,
    Coin.Dime,
    Coin.Nickel,
    Coin.Penny]

coins[0].rawValue
coins[1].rawValue


countWaysToBreakAmout(25, usingCoins: coins)

// Functional 
func countWaysToBreakAmount2 (amount: Int, usingCoins coins:Slice<Coin>) -> Int
{
    let (coin, smallerCoins) = (coins[0], coins[1..<coins.count])
    if(coin == .Penny) {
        return 1
    }
    let coinCounts = [Int](0...amount/coin.rawValue)
    return coinCounts.reduce(0) {
        (sum, coinCount) in
        let remainingAmount = amount - (coin.rawValue * coinCount)
        return sum +  countWaysToBreakAmount2(remainingAmount, usingCoins:smallerCoins)
    }
}





